﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FonShare.Classes.Data;
using FonShare.Classes;

namespace FonShare
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //UsernameTextBox.Text = "Seb";
            //PasswordTextBox.Text = "toto";
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            FS_DataClassesDataContext dataContext = new FS_DataClassesDataContext();
            List<FS_User> usersList = dataContext.FS_Users.Where(record => record.Username == UsernameTextBox.Text && record.Password == PasswordTextBox.Text).ToList();
            if (usersList.Count() == 1)
            {
                Session[FS_Constants.Session.USERID] = usersList.First().UserID;
                Server.Transfer("~/WebPages/Dashboard.aspx");
            }
            else
            {
                MessageLabel.Text = "Login or Password doesn't exist or is wrong, please check and try again.";
            }
        }
    }
}
